package com.queue.cli.handler;

import com.queue.common.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class ProducerHandler extends SimpleChannelInboundHandler<Protocol> {

    /**
     * 客户端连接成功就向服务端注册自己
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        register();
    }

    /**
     * 向服务器注册自己
     */
    private void register(){}

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Protocol protocol) throws Exception {

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("关闭与服务端的连接...");
        ctx.channel().close();
    }
}
